﻿# region Using System
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Runtime.InteropServices;//捕捉错误
# endregion

# region Using ArcGIS
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.esriSystem;//不用从引用加入
using ESRI.ArcGIS.Carto;//管理图层
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
# endregion


namespace popGis
{

    public partial class MainForm : Form
    {
        
        /// <summary>
        /// 从个人地理数据库中的名为name的要素集中得到要素图层
        /// </summary>
        /// <param name="name">要素集名字</param>
        /// <param name="thisFeatureLayer">抛出该要素图层</param>
        public void OpenFeatureLayerFromFeatureClassName(string name, out IFeatureLayer thisFeatureLayer)
        {
            thisFeatureLayer = new FeatureLayerClass();

            pWorkspace = OpenAccessWorkspace(mdbPath);
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

            IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(name);

            thisFeatureLayer.FeatureClass = pFeatureClass;
            thisFeatureLayer.Name = pFeatureClass.AliasName;
        }

        /// <summary>
        /// 打开指定路径的个人地理数据库（Access.mdb 格式）的工作空间
        /// </summary>
        /// <param name="thismdbPath">路径</param>
        /// <returns>工作空间</returns>
        public IWorkspace OpenAccessWorkspace(string thismdbPath)
        {
            IWorkspaceFactory _pWSF = new AccessWorkspaceFactoryClass();
            IPropertySet pPropertySet = new PropertySetClass();
            pPropertySet.SetProperty("DATABASE", thismdbPath);

            IWorkspace thisWorkspace = _pWSF.Open(pPropertySet, 0);

            return thisWorkspace;
        }








    }








    class MainFormSupport
    {
    }
}
